import 'dart:io';

import 'package:flutter/material.dart';
import 'package:multi_media/src/photo_hero.dart';

class PhotoShow extends StatelessWidget {
  ///local picture file
  final File? localFile;

  ///network picture url
  final String? netUrl;

  ///判断附件来源
  final bool isNetUrl;
  const PhotoShow(this.isNetUrl, {this.localFile, this.netUrl, Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return isNetUrl
        ? PhotoHero(
            isNetUrl,
            //源路由
            netUrl: netUrl!,
            width: 160,
            height: 100,
            onTap: () {
              //目的路由及目的路由框架搭建
              Navigator.of(context)
                  .push(MaterialPageRoute(builder: (BuildContext context) {
                return Scaffold(
                  appBar: buildAppBar(context),
                  body: Container(
                    padding: const EdgeInsets.all(16.0),
                    alignment: Alignment.center,
                    child: PhotoHero(isNetUrl,
                        netUrl: netUrl,
                        width: double.infinity,
                        height: double.infinity),
                  ),
                );
              }));
            },
          )
        : PhotoHero(
            isNetUrl,
            //源路由
            photo: localFile,
            width: 160,
            height: 100,
            onTap: () {
              //目的路由及目的路由框架搭建
              Navigator.of(context)
                  .push(MaterialPageRoute(builder: (BuildContext context) {
                return Scaffold(
                  appBar: buildAppBar(context),
                  body: Container(
                    padding: const EdgeInsets.all(16.0),
                    alignment: Alignment.center,
                    child: PhotoHero(
                      isNetUrl,
                      photo: localFile,
                      width: double.infinity,
                      height: double.infinity,
                    ),
                  ),
                );
              }));
            },
          );
  }

  AppBar buildAppBar(BuildContext context) {
    return AppBar(
      title: const Text(
        '照片详情',
        style: TextStyle(color: Colors.white),
      ),
      leading: goBackButton(context),
    );
  }

  IconButton goBackButton(BuildContext context) {
    return IconButton(
      onPressed: () {
        Navigator.pop(context);
      },
      icon: const Icon(
        Icons.arrow_back_ios,
        size: 20,
        color: Colors.white,
      ),
    );
  }
}
